#include <iostream>
#include <vector>
#include <memory.h>
#include <cstdio>
using namespace std;

struct node {
	int u, w;
	node(int v, int wi) {
		u = v;
		w = wi;
	}
};

vector<node> G[10005];
int ans;
int ai;
bool vis[10005];

void dfs(int x, int w) {
	if (vis[x]) return;
	vis[x] = 1;
	if (w > ans) {
		ans = w;
		ai = x;
	}
	for (unsigned i = 0; i < G[x].size(); ++i) {
		dfs(G[x][i].u, w + G[x][i].w);
	}
}

int main() {
	int x, y, w;
	while(cin >> x >> y >> w) {
		G[x].push_back(node(y, w));
		G[y].push_back(node(x, w));	
	}
	ans = -1;
	ai = 0;
	memset(vis, 0, sizeof(vis));
	dfs(1, 0);
	memset(vis, 0, sizeof(vis));
	ans = 0;
	dfs(ai, 0);
	cout << ans << endl;

	for (int i = 0; i <= 10001; ++i) {
		G[i].clear();
	}
	return 0;
}